package com.wnxy.mallserver.service.impl;

import com.wnxy.mallserver.entity.User;
import com.wnxy.mallserver.exception.AccountOrPasswordException;
import com.wnxy.mallserver.mapper.UserMapper;
import com.wnxy.mallserver.response.Message;
import com.wnxy.mallserver.service.UserService;
import com.wnxy.mallserver.vo.LoginVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    //登录验证
    @Override
    public User login(LoginVo loginVo) {
        //查询数据库
        User user = userMapper.queryByAccount(loginVo.getAccount());
        if(user == null || !user.getPassword().equals(loginVo.getPassword())){
            //在业务逻辑中，不满足业务逻辑的，通常抛运行异常（自定义异常）
            throw new AccountOrPasswordException(Message.ACCOUNT_OR_PASSWORD_ERROR);
        }
        return user;
    }
}
